<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: David
  Date: 2019/12/22
  Time: 21:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.Set" %>
<%@ page import="com.geping.etl.common.util.VariableUtils" %>
<%@ page import="com.geping.etl.common.entity.Sys_Auth_Role_Resource" %>
<%
    String path = request.getContextPath();
    //当前协议+网站域名+端口号+项目名+/ ==http://localhost:8080/EastBus/
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    //数据状态
    String status = (String) request.getAttribute("action");

    VariableUtils vu = (VariableUtils) request.getSession().getAttribute("vu");
    String role = vu.getRole();
    String dataStatus = request.getParameter("dataStatus");
    Set<Sys_Auth_Role_Resource> operateSet = vu.getOperateReportSet();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>数据处理页面</title>
    <%@include file="head.jsp" %>
    <style type="text/css">
        .demo-info {
            background: #FFFEE6;
            color: #8F5700;
            padding: 9px;
            margin-bottom: 2px;
            height: 10px;
            font-size: 12px
        }

        .demo-tip {
            width: 16px;
            height: 16px;
            margin-right: 8px;
            float: left;
        }

        .left, .right {
            width: 250px;
            height: 300px;
            float: left;
            overflow: scroll;
            border: 1px solid #ddd;
        }

        .center {
            float: left;
            width: 50px;
            height: 300px;
            position: relative;
        }

        #centerBox {
            width: 100%;
            position: absolute;
            top: 50%;
            margin-top: -45px;
        }

        .listTitle {
            width: 100%;
            height: 30px;
            line-height: 30px;
            text-align: center;
            background-color: rgb(245, 247, 250);
        }

        .goToButton {
            display: block;
            position: relative;
            width: 40px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            font-size: 20px;
            border-radius: 25px;
            background: #eee;
            margin: 0 auto 5px;
            cursor: pointer;
            border: 1px solid #dcdfe6;
            background-color: #f5f7fa;
            color: #c0c4cc;
            outline: none;
        }

        .checkBoxList {
            padding: 10px 15px;
        }

        .checkBoxList li {
            list-style: none;
            font-size: 12px;
            font-family: 微软雅黑;
            padding: 2px 0px;
        }

        .checkBoxList input {
            width: 15px;
            height: 15px;
        }

        .infoTitle {
            color: #3872f6;
            font-size: 15px;
        }

    </style>
</head>
<body>
<div class="demo-info" style="height: auto;border-radius: 5px;">
    <div style="margin-top:5px;color: black">
        <form id="searchForm" style="display: inline;"></form>
        <a class="easyui-linkbutton" id="search" data-options="iconCls:'icon-search'" href="javascript:;"
           onclick="filterData()">搜索</a>
    </div>
</div>
<div id="cc" class="easyui-layout" style="width:100%;height:500px">
    <div data-options="region:'center'" fit=true style="width: 100%;height: 100%;">
        <table id="dataGrid" style="height: 100%;"></table>
    </div>
</div>
<div id="dataGridToobar">
    <a href="dataCount?panelId=${panelId}" class="easyui-linkbutton" data-options="iconCls:'icon-return'">返回</a>
    <%
        if ("submit".equals(dataStatus)) {
    %>
    <a href="javascript:;" onclick="add()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加</a>
    <a href="javascript:;" onclick="modify()" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
    <a href="javascript:;" onclick="applyRemoveBefore()" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除</a>
    <a href="javascript:;" onclick="openImpDialog()" class="easyui-linkbutton" data-options="iconCls:'icon-page-excel'">导入</a>
    <a href="javascript:;" onclick="exportFile()" class="easyui-linkbutton"
       data-options="iconCls:'icon-download'">导出</a>
   <%-- <a href="javascript:;" onclick="submitBefore()" class="easyui-linkbutton"
       data-options="iconCls:'icon-easyicon-net-16'">提交</a>--%>
    <%
        }
    %>
    <%
        //"checker".equals(role)
        if ("check".equals(dataStatus)) {
    %>
    <a href="javascript:;" onclick="applyRemoveBefore()" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">申请删除</a>
    <a href="javascript:;" onclick="applyModifyBefore()" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">申请修改</a>
    <a href="javascript:;" onclick="exportFile()" class="easyui-linkbutton"
       data-options="iconCls:'icon-download'">导出</a>
    <a class="easyui-linkbutton" iconCls="icon-application-get" onclick="passBefore()">审核通过</a>
    <a class="easyui-linkbutton" iconCls="icon-cross" onclick="notPassBefore()">审核不通过</a>
    <a class="easyui-linkbutton" iconCls="icon-ok" onclick="agreeApplyBefore()">同意申请</a>
    <a class="easyui-linkbutton" iconCls="icon-cross" onclick="rejectApplyBefore()">拒绝申请</a>
    <%
        }
    %>
    <%
        //"checker".equals(role)
        if ("pass".equals(dataStatus)) {
    %>
    <a href="javascript:;" onclick="applyModifyBefore()" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">申请修改</a>
    <a href="javascript:;" onclick="applyRemoveBefore()" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">申请删除</a>
    <a href="javascript:;" onclick="exportFile()" class="easyui-linkbutton"
       data-options="iconCls:'icon-download'">导出</a>
    <%
                }
    %>
    <%--<a href="javascript:;" onclick="check()" class="easyui-linkbutton" data-options="iconCls:'icon-alert-yellow',plain:true">校验</a>--%>
</div>

<div id="dataDialog" class="easyui-dialog" title="添加" style="width:1050px;height:auto;"
     data-options="model:true,closed:true,toolbar:'#dataDialogToobar'">
    <form id="dataForm" style="width:900px;margin: 40px 0;" generate="false">
        <table id="dataTable" style="text-align: right">
            <tbody></tbody>
        </table>
    </form>
</div>
<div id="dataDialogToobar">
    <a href="javascript:;" id="saveButton" class="easyui-linkbutton" onclick="saveData()"
       data-options="iconCls:'icon-save'">保存</a>
    <a href="javascript:;" id="modifyButton" class="easyui-linkbutton" onclick="modifyData()"
       data-options="iconCls:'icon-save'">更新</a>
</div>


<div id="exportWidnow" class="easyui-dialog" title="数据导出"
     style="width: 400px;height: 300px;font-size: 15px;text-align: right"
     data-options="iconCls:'icon-excel-import',modal:true,collapsible:false,minimizable:false,maximizable:false,closed:true,toolbar:'#exportToobar'">

    <div style="margin: 10px 30px 10px 0px; ">
        <label>默认顺序并导出全部列:</label>
        <select id="exportOrder" class="easyui-combobox" name="defaultOrder" editable=false style="width: 150px"
                data-options="
               onSelect: function(res){
                    if (res.value == 'false') {
                        reload();
                        $('#shuttleBox').window('open');
                    }
               }
              ">
            <option value=true>是</option>
            <option value=false>否</option>
        </select>
    </div>
    <div style="margin: 10px 30px 10px 0px; ">
        <label>导出包含标题:</label>
        <select id="exportHead" class="easyui-combobox" name="containHead" editable=false style="width: 150px">
            <option value="true">是</option>
            <option value="false">否</option>
        </select>
    </div>
    <div style="margin: 10px 30px 10px 0px; ">
        <label>导出文件类型:</label>
        <select id="exportType" class="easyui-combobox" name="handlerType" editable=false style="width: 150px">
            <option value="excel">EXCEL</option>
            <option value="csv">CSV</option>
            <option value="txt">TXT</option>
        </select>
    </div>
    <div style="margin: 10px 30px 10px 0px; ">
        <label>TXT文件分割符:</label>
        <select id="exportSplit" class="easyui-combobox" name="split" editable=false style="width: 150px">
            <option value="44">,</option>
            <option value="35">#</option>
            <option value="126">~</option>
            <option value="42">*</option>
            <option value="45">-</option>
            <option value="94">^</option>
            <option value="124">|</option>
        </select>
    </div>

</div>
<div id="shuttleBox" class="easyui-window" data-options="closed:true,modal:true" title="指定导出顺序和导出字段">
    <div class="left">
        <div class="listTitle">默认列表</div>
        <ul id="leftUl" class="checkBoxList">
        </ul>
    </div>
    <div class="center">
        <div id="centerBox">
            <div id="goToButtonToRight" class="goToButton">
                >
            </div>
            <div id="goToButtonToLeft" class="goToButton" onclick="goLeft()">
                <
            </div>
        </div>
    </div>
    <div class="right">
        <div class="listTitle">导出/导入列表</div>
        <ul id="rightUl" class="checkBoxList">
        </ul>
    </div>
</div>
<div id="exportToobar">
    <a href="javascript:;" onclick="exportConfirm()" class="easyui-linkbutton"
       data-options="iconCls:'icon-ok',plain:true">确认</a>
</div>

<%--导入窗口--%>
<div id="uploadWidnow" class="easyui-window" title="数据导入"
     style="width:500px;height:200px;padding: 10px"
     data-options="iconCls:'icon-excel-import',modal:true,collapsible:false,minimizable:false,maximizable:false,closed:true">
    <div id="fileUpLoad">
        <form id="uploadForm" action="${serverUrl}/importExport/import" method="POST" enctype="multipart/form-data"
              style="display: inline-block;">
            选择文件导入：<input type="file" id="uploadFile" size="45" name="uploadFile" class="input"
                                onchange="fileSelected()"/>
            <input type="hidden" id="tableId" name="tableId">
            <input type="hidden" id="loginId" name="loginId">
            <br><br>
            模版名：<select class="easyui-combobox" name="template" id="template" style="width:200px;" editable=false>
            </select>
            <br><br>
            导入类型：
            <select id="templateImport" class="easyui-combobox" name="templateImport" style="width:200px;" editable=false>
            <option value="importAdd" selected="selected">导入新增</option>
            <option value="importCover" >导入覆盖</option>
            </select>

        </form>
<%--        <button id="importId" onclick="$.messager.progress({text:'正在解析中......'}); $('#uploadForm').submit()">导入--%>
<%--        </button>--%>
        <button id="importId" onclick="importExcels()">导入</button>
    </div>
</div>

<%--导入向导--%>
<div class="easyui-dialog" id="impDailog" title="导入向导" style="width: 600px;height: 400px;font-size: 15px;"
     data-options='modal:true, closed:true, onBeforeClose:function(){
        $("#switchType").show();
        $("#switchSheet").hide();
        $("#switchFile").hide();
        $("#switchRow").hide();
        $("#switchMap").hide();
        $("#splitTr").hide();
        $("#charsetTr").hide();
        $("#sheetList").empty();
        $("#uploadFile").val("");
        }' buttons='#importToobar'>
    <div id="switchType" style="width: 93%;height:60%;">
        <p class="infoTitle">您要选择哪种导入格式?</p>
        <fieldset style="width: 100%;height:100%; border: 1px grey dashed">
            <legend>导入类型</legend>
            <input type="radio" name="importType" value="excel"/> Excel文件(*.xlsx)
            <br/>
            <input type="radio" name="importType" value="csv"/> Csv文件(*.csv)
            <br/>
            <input type="radio" name="importType" value="txt"/> 文本文件(*.txt)
        </fieldset>
    </div>
    <div id="switchFile" style="height: 60%;width: 100%;display: none">
        <p class="infoTitle">您必须选择一个文件作为数据源</p>
        <div style="height: 30%;">
            <fieldset style="border: 1px grey dashed">
                <legend>导入从:</legend>
                <form id="uploadFileForm" action="${serverUrl}/importExport/resolve" method="POST"
                      enctype="multipart/form-data">
                    <input type="file" id="uploadFile" size="45" name="uploadFile" class="input"
                           onchange="fileSelected()"/>
                    <input type="hidden" id="handlerType" name="type">
                    <input type="hidden" id="loginId" name="loginId">
                </form>
            </fieldset>
        </div>

        <div id="switchSheet" style="height:90%;width:100%;margin-top:20px;display: none">
            <fieldset style="border: 1px grey dashed">
                <legend>选择要导入的Sheet:</legend>
                <form id="sheetList"></form>
            </fieldset>
        </div>
    </div>
    <div id="switchRow" style="width: 100%;display: none">
        <p class="infoTitle">定义一些附加选项</p>
        <table style="margin-left: 15px;">
            <tr>
                <td>
                    字段名行：
                </td>
                <td>
                    <input type="text" name="headRow" value="1" style="width: 170px; height: 18px;"/>
                <td>
            </tr>
            <tr>
                <td>
                    第一个数据行：
                </td>
                <td>
                    <input type="text" name="firstRow" value="2" style="width: 170px; height: 18px;"/>
                </td>
            </tr>
            <tr>
                <td>
                    最后一个数据行：
                </td>
                <td>
                    <input type="text" name="lastRow" style="width: 170px; height: 18px;"/>
                </td>
            </tr>
            <tr id="splitTr" style="display: none;">
                <td>
                    字段分割符：
                </td>
                <td>
                    <select id="lineSplit" name="lineSplit" editable=false
                            style="width:178px;height:23px;font-size:16px;border: 1px solid black;">
                        <option value=",">,</option>
                        <option value="#">#</option>
                        <option value="~">~</option>
                        <option value="*">*</option>
                        <option value="-">-</option>
                        <option value="^">^</option>
                        <option value="|">|</option>
                    </select>
                </td>
            </tr>
            <tr id="charsetTr" style="display: none;">
                <td>
                    请选择编码：
                </td>
                <td>
                    <select id="charset" name="charset" editable=false
                            style="width:178px;height:23px;font-size:16px;border: 1px solid black;">
                        <option value="GBK">GBK</option>
                        <option value="UTF-8">UTF-8</option>
                        <option value="GB2312">GB2312</option>
                        <option value="ISO-8859-1">ISO-8859-1</option>
                        <option value="UTF-16">UTF-16</option>
                        <option value="UTF-16BE">UTF-16BE</option>
                        <option value="UTF-16LE">UTF-16LE</option>
                        <option value="UTF-32">UTF-32</option>
                        <option value="UTF-32BE">UTF-32BE</option>
                        <option value="UTF-32LE">UTF-32LE</option>
                    </select>
                </td>
            </tr>
        </table>
    </div>
    <div id="switchMap" style="width: 100%;height:80%;display: none">
        <p class="infoTitle">您可以指定字段映射，设置映射来指定源字段和目的字段之间的关系</p>
        <div style="margin-left: 15px;">
            源表:
            <div id="sheetSelect">

            </div>
        </div>
        <div style="height: 80%; width:100%;margin-top: 20px;">
            <fieldset style="border: 1px grey dashed">
                <legend>请选择字段之间的映射关系:</legend>
                <table id="responseTable"></table>
            </fieldset>
        </div>
    </div>
</div>
<div id="importToobar">
    <a href="javascript:;" onclick="prevStep()" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true">上一步</a>
    <a href="javascript:;" onclick="nextStep()" class="easyui-linkbutton" data-options="iconCls:'icon-redo',plain:true">下一步</a>
</div>

<%--用于渲染 --%>
<script type="text/javascript">
    /**
     * 获取表的元数据,并设置表信息
     */
    function loadTableMetadata() {
        $.ajax({
            //async: false,
            url: '${serverUrl}/tableManage/tableMetadata?tableId=${tableId}&loginId=${loginId}',
            type: "GET",
            dataType: "json",
            //contentType: "application/json",
            success: function (res) {
                var title = res.data;
                if (res.code != '000000') {
                    title = "数据管理";
                }
                $('#dataGrid').attr("title", title);
            },
            error: function (error) {
                $.messager.alert('提示', "无法获取表元数据，请联系管理员!");
            }
        });
    }

    //获取表结构，初始化DataGrid
    $(function () {

        /**
         * 解决丢它老母的IE缓存问题
         */
        jQuery(function ($) {
            jQuery.ajaxSetup({
                cache: false
            });
        });
        //获取表的元数据,并设置表信息
        loadTableMetadata();
        $.ajax({
            //async: false,
            url: "${serverUrl}/tableManage/column?showHide=true&showBusiness=true&tableId=${tableId}",
            type: "GET",
            dataType: "json",
            //contentType: "application/json",
            success: function (res) {
                //获取数据表结构
                if (res != undefined && res.rows.length > 0) {
                    var rows = res.rows;
                    try { //生成dataGrid
                        generateDataGrid(rows);
                        //生成搜索结构
                        generateSearch(rows);
                        //生成表单结构
                        generateInput(rows);
                        //生成穿梭框
                        generateShuttle(rows);
                    } catch (e) {
                        $.messager.alert('提示', "渲染页面过程中发生错误，请联系管理员!");
                    }
                } else {
                    $.messager.alert('提示', "无法获取页面结构，请联系管理员!");
                }
            },
            error: function (error) {
                $.messager.alert('提示', "无法获取页面结构，请联系管理员!");
            }
        });
    });


    /**
     * 生成dataGrid结构
     * @param fields
     */
    function generateDataGrid(rows) {
        var fields = [];
        var field = {
            field: 'id',
            title: 'id',
            width: 20,
            align: 'center',
            checkbox: true
        }
        fields.push(field);
        for (var i = 0; i < rows.length; i++) {
            var row = rows[i];
            field = {
                field: row.name,
                title: row.comment,
                hidden: row.isHidden == 'Y' ? true : false,
                width: 100,
                align: 'center',
                formatter: function (value, row, index) {
                    if (value == null) {
                        return ""
                    }
                    return (value + "").replace("<script>", "").replace("<\\/script>", "");
                }
            }
            fields.push(field);
        }
        $('#dataGrid').datagrid({
            nowrap: true,
            url: '${serverUrl}/query?tableId=${tableId}&loginId=${loginId}&dataStatus=${dataStatus}',
            method: 'GET',
            fitColumns:true,
            fit: true,
            striped: true,
            pageList: [15, 20, 30],
            //singleSelect: true,
            pagination: true,
            rownumbers: true,
            toolbar: "#dataGridToobar",
            columns: [fields]
        });
    }

    /**
     * 生成搜索结构
     */
    function generateSearch(rows) {
        var element = document.getElementById("searchForm");
        for (var i = 0; i < rows.length; i++) {
            var row = rows[i];
            if (row.search == "N" || row.isHidden == "Y" || row.isBusiness == 'Y') {
                continue;
            }
            var label = document.createElement("label");
            label.innerText = row.comment + "：";
            var input = document.createElement("input");
            input.setAttribute("name", row.name);
            var textType = row.contextType;
            var dataOption = "";
            if (textType == "1") {
                input.className = "easyui-numberbox";
                var x = row.width - row.point;
                var max = "";
                while (x > 0) {
                    max += 9 + "";
                    x--;
                }
                var point = row.point > 0 ? row.point - 1 : 0;
                dataOption = "min:0,precision:" + point + ",max:" + max + ",";
                //处理最大值和小数位
            } else if (textType == "2") {
                input.className = "easyui-datebox";
                dataOption += "formatter:function(date){" +
                    "this.fmt = '" + row.dateFormat + "';" +
                    "return date.format('" + row.dateFormat + "', date);" +
                    "},parser:parser,";
            } else if (textType == "3") {
                input.className = "easyui-combobox";
                //处理url
                var combo = new Array();
                combo = rows[i].comboUrl.split("-");
                var value = "{id:'',value:'--请选择--'}";
                for (var j = 0; j < combo.length; j++) {
                    value += ",{id:'" + combo[j] + "',value:'" + combo[j] + "'}";
                }

                dataOption += "valueField:'id',textField:'value'," +
                    "data:[" + value + "]";
            } else {
                input.className = "easyui-validatebox";
                input.setAttribute("style", "height:18px;line-height:20px;")
            }
            input.setAttribute("data-options", dataOption);
            element.appendChild(label);
            element.appendChild(input);

        }
        if (element.children.length <= 0) {
            document.getElementById("search").style.display = "none";
        }
        //动态渲染
        $.parser.parse($('#searchForm'));
    }

    /**
     * 生成编辑form
     * @param inputs
     */
    function generateInput(rows) {
        var tableElement = document.getElementById("dataTable").children[0];
        var dataForm = document.getElementById("dataForm");
        var trElement;
        var index = 0;
        for (var i = 0; i < rows.length; i++) {

            if ((index + 3) % 3 == 0) {
                trElement = document.createElement("tr");
                trElement.style.width = "900px";
                tableElement.appendChild(trElement);
            }
            var tdElement = document.createElement("td");
            tdElement.style.width = "300px";
            tdElement.style.wordBreak = "keep-all";
            var labelElement = document.createElement("label");
            labelElement.style.fontSize = "14px";
            labelElement.style.fontFamily = "Consolas,'Microsoft YaHei UI'";
            labelElement.innerText = rows[i].comment + ":";

            var inputElement = document.createElement("input");
            inputElement.setAttribute("id", rows[i].name);
            inputElement.setAttribute("name", rows[i].name);
            var dataOption = "";
            //处理文本框类型
            var textType = rows[i].contextType;
            if (textType == "1") {
                inputElement.className = "easyui-numberbox";
                var x = rows[i].width - rows[i].point;
                var max = "";
                while (x > 0) {
                    max += 9 + "";
                    x--;
                }
                //var point = rows[i].point > 0 ? rows[i].point - 1 : 0;
                var point = rows[i].point > 0 ? rows[i].point : 0;
                x = point;
                var p = "";
                while (x > 0) {
                    p += 9 + "";
                    x--;
                }
                max += "." + p;
                //去掉小数点
                dataOption += "min: -" + max + ",precision:" + point + ",max:" + max + ",";
                //处理最大值和小数位
            } else if (textType == "2") {

                if (rows[i].dateFormat != "yyyy-MM-dd HH:mm:ss") {
                    inputElement.className = "easyui-datebox";
                    dataOption += "editable:false,formatter:function(date){" +
                        "this.fmt = '" + rows[i].dateFormat + "';" +
                        "return date.format('" + rows[i].dateFormat + "', date);" +
                        "},parser:parser,";
                } else {
                    inputElement.className = "easyui-datetimebox";
                }
            } else if (textType == "3") {
                inputElement.className = "easyui-combobox";
                //处理url
                var combo = new Array();
                combo = rows[i].comboUrl.split("-");
                var value = "{id:'',value:'--请选择--'}";
                for (var j = 0; j < combo.length; j++) {
                    value += ",{id:'" + combo[j] + "',value:'" + combo[j] + "'}";
                }
                dataOption += "valueField:'id',textField:'value'," +
                    "data:[" + value + "]";

            } else {
                inputElement.className = "easyui-validatebox";
                inputElement.setAttribute("style", "height:18px;line-height:20px;")
                //处理最大长度
                dataOption += "validType:'length[0, " + rows[i].width + "]',";
            }
            //处理必填项
            if (rows[i].notNull == "Y") {
                dataOption += "required:true,";
            }
            //处理隐藏域
            if (rows[i].isHidden == "Y" || rows[i].isBusiness == 'Y') {
                inputElement.setAttribute("type", "hidden");
                dataForm.appendChild(inputElement);
            } else {
                inputElement.setAttribute("data-options", dataOption);
                tdElement.appendChild(labelElement);
                tdElement.appendChild(inputElement);
                trElement.appendChild(tdElement);
                index++;
            }
        }
        //动态渲染
        $.parser.parse($("#dataForm"));
    }

    /**
     * 生成穿梭框列表
     * @param rows
     */
    function generateShuttle(rows) {
        var leftUl = document.getElementById("leftUl");
        for (var i = 0; i < rows.length; i++) {
            var row = rows[i];
            if (row.isHidden == 'N' && row.isBusiness != 'Y') {
                var li = document.createElement("li");
                var input = document.createElement("input");
                var label = document.createElement("label");
                label.innerText = row.comment;
                input.setAttribute("name", row.name);
                input.setAttribute("checked", true);
                input.setAttribute("type", "checkbox");
                li.appendChild(input);
                li.appendChild(label);
                leftUl.appendChild(li);
            }
        }
    }

</script>
<script>
    /**
     * 搜索数据
     */
    function filterData() {
        var queryArray = resolveSearch();
        //组织搜索数据
        $('#dataGrid').datagrid({
            queryParams: {
                searchParams: JSON.stringify(queryArray)
            }
        });
    }

    function resolveSearch() {
        var formData = $("#searchForm").serializeArray();
        //去除空值
        var params = [];
        for (var i = 0; i < formData.length; i++) {
            if (formData[i].value) {
                params.push(formData[i]);
            }
        }
        return params;
    }


    /**
     * 添加按钮
     */
    function add() {
        $("#dataForm").form('clear');
        $("#dataDialog").dialog({'title': '添加'});
        $("#saveButton").show();
        $("#modifyButton").hide();
        $("#dataDialog").dialog('open');
    }

    /**
     * 修改按钮
     */
    function modify() {
        var rows = $("#dataGrid").datagrid('getSelections');
        if (rows.length != 1) {
            $.messager.alert('提示', '请选择一行数据进行操作!', 'info');
            return;
        }
        $("#dataDialog").dialog({'title': '修改'});
        $("#dataForm").form('reset');
        $("#dataForm").form('load', rows[0]);
        $("#modifyButton").show();
        $("#saveButton").hide()
        $("#dataDialog").dialog('open');
    }

    /**
     * 保存数据
     * @param mdoel
     */
    function saveData() {
        if ($("#dataForm").form('validate')) {
            var formData = $("#dataForm").serializeArray();
            var data = {
                "data": {
                    "table": {
                        "tableId": ${tableId}
                    },
                    "result": formData
                },
                "loginId": '${loginId}'
            }
            $.ajax({
                url: '${serverUrl}/query',
                type: 'POST',
                dataType: 'JSON',
                contentType: "application/json",
                data: JSON.stringify(data),
                success: function (res) {
                    if (res.code == "000000") {
                        $.messager.alert('提示', "处理成功", "info");
                    } else {
                        $.messager.alert('提示', res.msg, "error");
                    }
                    $("#dataDialog").dialog('close');
                    $('#dataGrid').datagrid('reload');
                },
                error: function (error) {
                    $.messager.alert('提示', "处理失败", "error");
                }
            })
        }
    }

    /**
     * 修改数据
     */
    function modifyData() {
        if ($("#dataForm").form('validate')) {
            var formData = $("#dataForm").serializeArray();
            var data = {
                "data": {
                    "table": {
                        "tableId": ${tableId}
                    },
                    "result": formData
                },
                "loginId": '${loginId}'
            }
            $.ajax({
                url: '${serverUrl}/query',
                type: 'PUT',
                dataType: 'JSON',
                contentType: "application/json",
                data: JSON.stringify(data),
                success: function (res) {
                    if (res.code == "000000") {
                        $.messager.alert('提示', "处理成功", "info");
                    } else {
                        $.messager.alert('提示', res.msg, "error");
                    }
                    $("#dataDialog").dialog('close');
                    $('#dataGrid').datagrid('reload');
                },
                error: function (error) {
                    $.messager.alert('提示', "处理失败", "error");
                }
            })
        }
    }

    function remove() {
        var rows = $("#dataGrid").datagrid('getSelections');
        if (rows.length <= 0) {
            $.messager.alert('提示', '请至少选择一行数据进行操作!', 'info');
            return;
        }

        var idArray = new Array();
        for (var i = 0; i < rows.length; i++) {
            var row = rows[i];
            if (row.SERIALNO == undefined || row.SERIALNO == '') {
                $.messager.alert('提示', '无法解析标识数据,处理失败!', 'error');
                return;
            }
            idArray.push(row.SERIALNO);
        }
        var data = {
            "data": {
                "table": {
                    "tableId": ${tableId}
                },
                "result": idArray
            },
            "loginId": '${loginId}'
        }
        $.messager.confirm('确认', '您确认要进行申请删除操作吗?', function (r) {
            if (r) {
                $.ajax({
                    url: '${serverUrl}/query',
                    type: 'DELETE',
                    dataType: 'JSON',
                    contentType: "application/json",
                    data: JSON.stringify(data),
                    success: function (res) {
                        if (res.code == "000000") {
                            $.messager.alert('提示', "处理成功", "info");
                        } else {
                            $.messager.alert('提示', res.msg, "error");
                        }
                        $('#dataGrid').datagrid('reload');
                    },
                    error: function (error) {
                        $.messager.alert('提示', "处理失败", "error");
                    }
                })
            }
        });
    }

    function exportFile() {
        $("#exportWidnow").dialog('open');
    }

    function submitBefore() {
        //如果有搜索条件按搜索条件提交
        var params = resolveSearch();
        if (params && params.length > 0) {
            $.messager.confirm('确认', '您添加了搜索条件是否按搜索条件提交?', function (r) {
                if (r) {
                    console.log(params);
                    submit([], JSON.stringify(params));
                } /*else {
                    params = [];
                    //判断是否选择了数据
                    var rows = $("#dataGrid").datagrid('getSelections');
                    if (rows.length == 0) {
                        $.messager.confirm('确认', '您没有选择任何数据,是否要提交所有待提交数据?', function(r){
                            if (r) {
                                submit([], "");
                            }
                        })
                    } else {
                        $.messager.confirm('确认', '您确认要提交所选数据吗?', function(r){
                            if (r) {
                                var ids = new Array();
                                for (var i = 0; i < rows.length; i++) {
                                    ids.push(rows[i].SERIALNO);
                                }
                                submit(ids, "");
                            }
                        })
                    }
                }*/
            })
        } else {
            var rows = $("#dataGrid").datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.confirm('确认', '您没有选择任何数据,是否要提交所有待提交数据?', function (r) {
                    if (r) {
                        submit([], "");
                    }
                })
            } else {
                $.messager.confirm('确认', '您确认要提交所选数据吗?', function (r) {
                    if (r) {
                        var ids = new Array();
                        for (var i = 0; i < rows.length; i++) {
                            ids.push(rows[i].SERIALNO);
                        }
                        submit(ids, "");
                    }
                })
            }
        }
    }

    function submit(result, searchParams) {
        var data = {
            "data": {
                "table": {
                    "tableId": ${tableId}
                },
                "result": result,
                "searchParams": searchParams,
                "dataStatus": '${dataStatus}'
            },
            "loginId": '${loginId}'
        }
        $.ajax({
            url: '${serverUrl}/query/submit',
            type: 'PUT',
            dataType: 'JSON',
            contentType: "application/json",
            data: JSON.stringify(data),
            success: function (res) {
                if (res.code == "000000") {
                    $.messager.alert('提示', "处理成功", "info");
                } else {
                    $.messager.alert('提示', res.msg, "error");
                }
                $('#dataGrid').datagrid('reload');
            },
            error: function (error) {
                $.messager.alert('提示', "处理失败", "error");
            }
        })
    }

    function notPassBefore() {
        var params = resolveSearch();
        if (params && params.length > 0) {
            $.messager.prompt('确认', '您添加了搜索条件是否按搜索条件审核不通过?', function (r) {
                if (r) {
                    notPass([], JSON.stringify(params), r);
                } else {
                    $.messager.alert('操作提示', '审核不通过原因必填', 'info');
                }
            })
        } else {
            var rows = $("#dataGrid").datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.prompt('确认', '您没有选择任何数据,是否要审核不通过所有提交数据?', function (r) {
                    if (r) {
                        notPass([], "", r);
                    } else {
                        $.messager.alert('操作提示', '审核不通过原因必填', 'info');
                    }
                })
            } else {
                $.messager.prompt('确认', '您确认要审核不通过所选数据吗?', function (r) {
                    if (r) {
                        var ids = new Array();
                        for (var i = 0; i < rows.length; i++) {
                            if (rows[i].STATUS == '1') {
                                $.messager.alert('错误', '不能对操作名不为空的数据进行操作!', 'error');
                                return;
                            }
                            ids.push(rows[i].SERIALNO);
                        }
                        notPass(ids, "", r);
                    } else {
                        $.messager.alert('操作提示', '审核不通过原因必填', 'info');
                    }
                })
            }
        }
    }

    function notPass(result, searchParams, notPassMark) {
        var data = {
            "data": {
                "table": {
                    "tableId": ${tableId}
                },
                "result": result,
                "notPassMark": notPassMark,
                "searchParams": searchParams,
                "dataStatus": '${dataStatus}'
            },
            "loginId": '${loginId}'
        }
        $.ajax({
            url: '${serverUrl}/query/notPass',
            type: 'PUT',
            dataType: 'JSON',
            contentType: "application/json",
            data: JSON.stringify(data),
            success: function (res) {
                if (res.code == "000000") {
                    $.messager.alert('提示', "处理成功", "info");
                } else {
                    $.messager.alert('提示', res.msg, "error");
                }
                $('#dataGrid').datagrid('reload');
            },
            error: function (error) {
                $.messager.alert('提示', "处理失败", "error");
            }
        })
    }


    function agreeApplyBefore() {
        var params = resolveSearch();
        if (params && params.length > 0) {
            $.messager.confirm('确认', '您添加了搜索条件是否按搜索条件同意申请?', function (r) {
                if (r) {
                    agreeApply([], JSON.stringify(params));
                }
            })
        } else {
            var rows = $("#dataGrid").datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.confirm('确认', '您没有选择任何数据,是否要同意申请所有提交数据?', function (r) {
                    if (r) {
                        agreeApply([], "");
                    }
                })
            } else {
                $.messager.confirm('确认', '您确认要同意申请所选数据吗?', function (r) {
                    if (r) {
                        var ids = new Array();
                        for (var i = 0; i < rows.length; i++) {
                            if (rows[i].STATUS == '2') {
                                $.messager.alert('错误', '不能对操作名为空的数据进行操作!', 'error');
                                return;
                            }
                            ids.push(rows[i].SERIALNO);
                        }
                        agreeApply(ids, "");
                    }
                })
            }
        }
    }

    function agreeApply(result, searchParams) {
        var data = {
            "data": {
                "table": {
                    "tableId": ${tableId}
                },
                "result": result,
                "searchParams": searchParams,
                "dataStatus": '${dataStatus}'
            },
            "loginId": '${loginId}'
        }
        $.ajax({
            url: '${serverUrl}/query/agreeApply',
            type: 'PUT',
            dataType: 'JSON',
            contentType: "application/json",
            data: JSON.stringify(data),
            success: function (res) {
                if (res.code == "000000") {
                    $.messager.alert('提示', "处理成功", "info");
                } else {
                    $.messager.alert('提示', res.msg, "error");
                }
                $('#dataGrid').datagrid('reload');
            },
            error: function (error) {
                $.messager.alert('提示', "处理失败", "error");
            }
        })
    }

    function rejectApplyBefore() {
        var params = resolveSearch();
        if (params && params.length > 0) {
            $.messager.confirm('确认', '您添加了搜索条件是否按搜索条件拒绝申请?', function (r) {
                if (r) {
                    rejectApply([], JSON.stringify(params));
                }
            })
        } else {
            var rows = $("#dataGrid").datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.confirm('确认', '您没有选择任何数据,是否要拒绝申请所有提交数据?', function (r) {
                    if (r) {
                        rejectApply([], "");
                    }
                })
            } else {
                $.messager.confirm('确认', '您确认要拒绝申请所选数据吗?', function (r) {
                    if (r) {
                        var ids = new Array();
                        for (var i = 0; i < rows.length; i++) {
                            if (rows[i].STATUS == '2') {
                                $.messager.alert('错误', '不能对操作名为空的数据进行操作!', 'error');
                                return;
                            }
                            ids.push(rows[i].SERIALNO);
                        }
                        rejectApply(ids, "");
                    }
                })
            }
        }
    }

    function rejectApply(result, searchParams) {
        var data = {
            "data": {
                "table": {
                    "tableId": ${tableId}
                },
                "result": result,
                "searchParams": searchParams,
                "dataStatus": '${dataStatus}'
            },
            "loginId": '${loginId}'
        }
        $.ajax({
            url: '${serverUrl}/query/rejectApply',
            type: 'PUT',
            dataType: 'JSON',
            contentType: "application/json",
            data: JSON.stringify(data),
            success: function (res) {
                if (res.code == "000000") {
                    $.messager.alert('提示', "处理成功", "info");
                } else {
                    $.messager.alert('提示', res.msg, "error");
                }
                $('#dataGrid').datagrid('reload');
            },
            error: function (error) {
                $.messager.alert('提示', "处理失败", "error");
            }
        })
    }

    function passBefore() {
        var params = resolveSearch();
        if (params && params.length > 0) {
            $.messager.confirm('确认', '您添加了搜索条件是否按搜索条件审核通过?', function (r) {
                if (r) {
                    pass([], JSON.stringify(params));
                }
            })
        } else {
            var rows = $("#dataGrid").datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.confirm('确认', '您没有选择任何数据,是否要审核通过所有提交数据?', function (r) {
                    if (r) {
                        pass([], "");
                    }
                })
            } else {
                $.messager.confirm('确认', '您确认要审核通过所选数据吗?', function (r) {
                    if (r) {
                        var ids = new Array();
                        for (var i = 0; i < rows.length; i++) {
                            console.log("rows[i]=", rows[i]);
                            if (rows[i].STATUS != '2') {
                                $.messager.alert('错误', '不能对有操作名的数据进行操作!', 'error');
                                return;
                            }
                            ids.push(rows[i].SERIALNO);
                        }
                        pass(ids, "");
                    }
                })
            }
        }
    }

    function pass(result, searchParams) {
        var data = {
            "data": {
                "table": {
                    "tableId": ${tableId}
                },
                "result": result,
                "searchParams": searchParams,
                "dataStatus": '${dataStatus}'
            },
            "loginId": '${loginId}'
        }
        $.ajax({
            url: '${serverUrl}/query/pass',
            type: 'PUT',
            dataType: 'JSON',
            contentType: "application/json",
            data: JSON.stringify(data),
            success: function (res) {
                if (res.code == "000000") {
                    $.messager.alert('提示', "处理成功", "info");
                } else {
                    $.messager.alert('提示', res.msg, "error");
                }
                $('#dataGrid').datagrid('reload');
            },
            error: function (error) {
                $.messager.alert('提示', "处理失败", "error");
            }
        })
    }

    function applyModifyBefore() {
        var params = resolveSearch();
        if (params && params.length > 0) {
            $.messager.confirm('确认', '您添加了搜索条件是否按搜索条件申请修改?', function (r) {
                if (r) {
                    applyModify([], JSON.stringify(params));
                }
            })
        } else {
            var rows = $("#dataGrid").datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.confirm('确认', '您没有选择任何数据,是否要申请修改所有提交数据?', function (r) {
                    if (r) {
                        applyModify([], "");
                    }
                })
            } else {
                $.messager.confirm('确认', '您确认要申请修改所选数据吗?', function (r) {
                    if (r) {
                        var ids = new Array();
                        for (var i = 0; i < rows.length; i++) {
                            /*                if (rows[i].STATUS != '0') {
                                                $.messager.alert('错误','不能对操作名不为空的数据进行操作!','error');
                                                return;
                                            }*/
                            ids.push(rows[i].SERIALNO);
                        }
                        applyModify(ids, "");
                    }
                })
            }
        }
    }

    function applyModify(result, searchParams) {
        var data = {
            "data": {
                "table": {
                    "tableId": ${tableId}
                },
                "result": result,
                "searchParams": searchParams,
                "dataStatus": '${dataStatus}'
            },
            "loginId": '${loginId}'
        }
        $.ajax({
            url: '${serverUrl}/query/applyModify',
            type: 'PUT',
            dataType: 'JSON',
            contentType: "application/json",
            data: JSON.stringify(data),
            success: function (res) {
                if (res.code == "000000") {
                    $.messager.alert('提示', "处理成功", "info");
                } else {
                    $.messager.alert('提示', res.msg, "error");
                }
                $('#dataGrid').datagrid('reload');
            },
            error: function (error) {
                $.messager.alert('提示', "处理失败", "error");
            }
        })
    }

    function applyRemoveBefore() {
        var params = resolveSearch();
        if (params && params.length > 0) {
            $.messager.confirm('确认', '您添加了搜索条件是否按搜索条件申请删除?', function (r) {
                if (r) {
                    applyRemove([], JSON.stringify(params));
                }
            })
        } else {
            var rows = $("#dataGrid").datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.confirm('确认', '您没有选择任何数据,是否要申请删除所有提交数据?', function (r) {
                    if (r) {
                        applyRemove([], "");
                    }
                })
            } else {
                $.messager.confirm('确认', '您确认要申请删除所选数据吗?', function (r) {
                    if (r) {
                        var ids = new Array();
                        for (var i = 0; i < rows.length; i++) {
                            /*if (rows[i].STATUS != '0') {
                                $.messager.alert('错误','不能对操作名不为空的数据进行操作!','error');
                                return;
                            }*/
                            ids.push(rows[i].SERIALNO);
                        }
                        applyRemove(ids, "");
                    }
                })
            }
        }
    }

    function applyRemove(result, searchParams) {
        var data = {
            "data": {
                "table": {
                    "tableId": ${tableId}
                },
                "result": result,
                "searchParams": searchParams,
                "dataStatus": '${dataStatus}'
            },
            "loginId": '${loginId}'
        }
        console.log(data);
        $.ajax({
            url: '${serverUrl}/query/applyRemove',
            type: 'PUT',
            dataType: 'JSON',
            contentType: "application/json",
            data: JSON.stringify(data),
            success: function (res) {
                if (res.code == "000000") {
                    $.messager.alert('提示', "处理成功", "info");
                } else {
                    $.messager.alert('提示', res.msg, "error");
                }
                $('#dataGrid').datagrid('reload');
            },
            error: function (error) {
                $.messager.alert('提示', "处理失败", "error");
            }
        })
    }


    /**
     *
     */
    function exportConfirm() {
        //解析导出条件
        //var exportAll = $("#exprotAll").checked;
        // var exportOrder = document.getElementById("exportOrder").checked;
        // var exportHead = document.getElementById("exportHead").checked;
        var exportOrder = $("#exportOrder").combobox("getValue");
        var exportHead = $("#exportHead").combobox("getValue");
        var exportType = $("#exportType").combobox("getValue");
        var exportSplit = $("#exportSplit").combobox("getValue");

        const rows = $("#dataGrid").datagrid('getSelections');
        var serialno = [];
        for (var i = 0; i < rows.length; i++) {
            var row = rows[i];
            serialno.push(row.SERIALNO);
        }
        if (rows.length == 0) {
            serialno = [];
        }
        //解析查询条件=
        var queryData = resolveSearch();

        if (queryData.length > 0) {
            $.messager.confirm('确认', '搜索条件不为空是否按照搜索条件进行导出?', function (r) {
                if (r) {
                    queryData = JSON.stringify(queryData);
                    exportExec(exportOrder, exportHead, exportType, exportSplit, queryData, serialno);
                } else {
                    exportExec(exportOrder, exportHead, exportType, exportSplit, "", serialno);
                }
            })
        } else {
            exportExec(exportOrder, exportHead, exportType, exportSplit, "", serialno);
        }
    }

    function exportExec(exportOrder, exportHead, exportType, exportSplit, searchData, serialno) {
        var heads = [];
        if (exportOrder == 'false') {
            //解析穿梭框
            heads = getChecked();
            if (heads.length <= 0) {
                $.messager.alert('提示', "您未选择默认导出,请指定导出列", "info");
                return;
            }
        }

        //构造请求参数
        var data = {
            "data": {
                "table": {
                    "tableId": ${tableId}
                },
                "handlerType": exportType,
                "excel": {
                    "singleSheet": true,
                    "sheets": [{
                        "heads": heads,
                        "importCells": [1, 2, 3],
                        "startRow": 0,
                        "endRow": 1000,
                        "containHead": exportHead,
                        "defaultOrder": exportOrder
                    }]
                },
                "csvOrTxtVo": {
                    "containHead": exportHead,
                    "defaultOrder": exportOrder,
                    "heads": heads,
                    "split": exportSplit
                },
                "serials": serialno,
                "searchParams": searchData,
                "dataStatus": '${dataStatus}'
            },
            "loginId": '${loginId}'
        }
        console.log("data=", JSON.stringify(data));
        //开始导出
        $.messager.progress({text: '正在写入中......'});
        $.ajax({
            url: '${serverUrl}/importExport',
            type: 'POST',
            dataType: 'JSON',
            contentType: "application/json",
            data: JSON.stringify(data),
            success: function (res) {
                if (res.code == "000000") {
                    var url = encodeURI("${serverUrl}/importExport?fileId=" + res.data);
                    window.location.href = url;
                    $.messager.progress('close');
                    $("#exportWidnow").dialog('close');
                } else {
                    $.messager.progress('close');
                    $.messager.alert('提示', res.msg, "error");
                }
                $('#dataGrid').datagrid('reload');
            },
            error: function (error) {
                $.messager.progress('close');
                $.messager.alert('提示', "处理失败", "error");
            }
        })
    }

    /**
     *
     *
     * */
    function openImpDialog() {
        $("#template").combobox("clear");
        $("#uploadFile").val("");
        $('#uploadWidnow').window('open');
    }

    function fileSelected() {
        var file = document.getElementById("uploadFile").files[0];
        var fileName = file.name;
        var fileType = fileName.substring(fileName.lastIndexOf('.'), fileName.length);
        var handlerType = "";

        if (fileType == ".xlsx") {
            handlerType = '1';
        } else if (fileType == ".csv") {
            handlerType = '2';
        } else if (fileType == ".txt") {
            handlerType = '3';
        } else {
            $.messager.alert('错误', "不支持的文件类型,请重新选择文件！", 'error');
            return;
        }


        //获取此内型是否有默认模板，或者此类型是否有模板
        $.ajax({
            url: '${serverUrl}/templateManager',
            method: 'GET',
            async: false,
            data: {
                searchParams: JSON.stringify([
                    {name: 'TABLEID', value: '${tableId}'},
                    //{name: 'ISDEFAULT', value: 'Y'},
                    {name: 'TEMPLATETYPE', value: handlerType}
                ])
            },
            success: function (res) {
                if (res && res.total > 0) {
                    var rows = res.rows;
                    $("#template").combobox({
                        valueField: 'serialNo',
                        textField: 'name',
                        data: rows,
                        onLoadSuccess: function () {
                            for (var row in rows) {
                                if (rows[row].isDefault == 'Y') {
                                    $(this).combobox("select", rows[row].serialNo);
                                    break;
                                }
                            }
                        }
                    });
                } else {
                    $.messager.alert('提示', "无法查找到此类型的模板文件,请先去导入数据表管理模块添加导入模板吧!", 'info');
                    $("#uploadWidnow").window("close");
                    return;
                }
            },
            error: function (err) {
                $.messager.alert('提示', "无法获取模板定义文件,请重试!", 'info');
                return;
            }
        })

        //$("#template").combobox("getValue");

        $("#loginId").val('${loginId}');
        $("#tableId").val('${tableId}');

        // //填充表单并提交
        // $("#handlerType").val(handlerType);
        // $("#loginId").val('${loginId}');
        // $.messager.progress({text: '文件正在解析中......'});
        // $("#uploadFileForm").submit();
    }

    function columnSelect(target) {
        var selectSheet = $("#sheetOptions").val();
        var resources = step.getResources();
        var resource = resources[selectSheet];
        var checkbox = $(target).parent().prev().prev().children()[0];
        var name = checkbox.value;
        var checked = checkbox.checked;
        for (var i = 0; i < resource.length; i++) {
            var r = resource[i];
            if (r.resource == name) {
                r.column = $(target).val();
                r.checked = checked;
                break;
            }
        }
    }
    //导入
    function importExcels(){
        var selecteds =$('#templateImport').combobox('getText');
        if(selecteds == "导入覆盖"){
            $.messager.confirm('确认', '您确认要覆盖全部数据吗?', function (r) {
                ifImportExcel(r);
            });
        }else {
            $.messager.confirm('确认', '您确认要导入新增数据吗?', function (r) {
                ifImportExcel(r);
        });
        }
    }
    //导入封装方法
    function ifImportExcel(r){
        if(r){
            $.messager.progress({text:'正在解析中......'});
            var fromData = new FormData($("#uploadForm")[0]);
            $.ajax({
                type:"post",
                url : '${serverUrl}/importExport/import',
                data:fromData,
                processData: false,//告诉jQuery不要去处理发送的数据
                contentType:false,//告诉jQuery不要去设置Content-Type请求头
                dataType : 'json',
                success : function(data){
                    $("#uploadWidnow").window("close");
                    $.messager.progress('close');
                    if(data.code == '000000'){
                        $.messager.alert('提示',"导入成功",'info');
                        $('#dataGrid').datagrid('reload');
                    }else if(data.code == '000002'){
                        $.messager.alert('提示', '导入数据校验错误，请查看错误信息!', "error");
                        var url = encodeURI("${serverUrl}/importExport?fileId=" + data.msg);
                        window.location.href = url;
                    }else {
                        $.messager.alert('提示', data.msg, "info");
                    }
                },
            });
        }
    }

    <%--$(function () {--%>
    <%--    try {--%>
    <%--        $('#uploadForm').ajaxForm(function (data) {--%>
    <%--            var res = data;--%>
    <%--            if (res.code == '000000') {--%>
    <%--                $.messager.alert('提示', "导入成功", "info");--%>
    <%--            } else if (res.code == '000002') {--%>
    <%--                $.messager.alert('提示', '导入数据校验错误，请查看错误信息!', "error");--%>
    <%--                var url = encodeURI("${serverUrl}/importExport?fileId=" + res.msg);--%>
    <%--                window.location.href = url;--%>
    <%--            } else {--%>
    <%--                $.messager.alert('提示', res.msg, "info");--%>
    <%--            }--%>
    <%--                    $('#dataGrid').datagrid('reload');--%>
    <%--                    $.messager.progress('close');--%>
    <%--                    $("#uploadWidnow").window("close");--%>
    <%--        });--%>
    <%--    } catch (error) {--%>
    <%--        $.messager.progress('close');--%>
    <%--        $.messager.alert('提示', "处理失败!", "info");--%>
    <%--    }--%>
    <%--})--%>

</script>

<%--在date 原型链上重写 format 方法--%>
<script type="text/javascript">
    Date.prototype.format = function (fmt, date) {
        var o = {
            "M+": date.getMonth() + 1,                 //月份
            "d+": date.getDate(),                    //日
            "h+": date.getHours(),                   //小时
            "m+": date.getMinutes(),                 //分
            "s+": date.getSeconds(),                 //秒
            "q+": Math.floor((date.getMonth() + 3) / 3), //季度
            "S": date.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            }
        }

        return fmt;
    }

    //日期解析方法
    function parser(s) {
        if (!s) {
            return new Date();
        }
        //获取格式
        var format = this.fmt;
        switch (format) {
            case 'yyyy-MM-dd':
            case 'yyyy/MM/dd':
                return new Date(s);
            case 'yy-MM-dd':
            case 'yy/MM/dd':
                s = '20' + s;
                return new Date(s);
            case 'yyyy年MM月dd日':
                s = s.replace(/年/g, '/').replace(/月/g, '/').replace(/日/g, '');
                return new Date(s);
            case 'yy年MM月dd日':
                s = s.replace(/年/g, '/').replace(/月/g, '/').replace(/日/g, '');
                s = '20' + s;
                return new Date(s);
            default:
                return new Date(s);
        }
    }
</script>
<script type="text/javascript">

    window.onload = function () {
        var goToButtonToRight = document.getElementById("goToButtonToRight");
        goToButtonToRight.addEventListener("click", goRight, false);
        var goToButtonToLeft = document.getElementById("goToButtonToLeft");
        goToButtonToLeft.addEventListener("click", goLeft, false);
    }


    function goRight() {
        var leftUl = document.getElementById("leftUl");
        var rightUl = document.getElementById("rightUl");
        var liList = getLiElements(leftUl);
        for (var i = 0; i < liList.length; i++) {
            var li = liList[i];
            leftUl.removeChild(li);
            rightUl.appendChild(li);
        }
    }

    function goLeft() {
        var leftUl = document.getElementById("leftUl");
        var rightUl = document.getElementById("rightUl");
        var liList = getLiElements(rightUl);
        for (var i = 0; i < liList.length; i++) {
            var li = liList[i];
            rightUl.removeChild(li);
            leftUl.appendChild(li);
        }
    }

    function getLiElements(ulElement) {
        var liElement = ulElement.getElementsByTagName("li");
        var liList = [];
        for (var i = 0; i < liElement.length; i++) {
            var li = liElement[i];
            var checkBox = li.firstElementChild;
            if (checkBox.checked) {
                liList.push(li);
            }
        }
        return liList;
    }

    function reload() {
        var rightUl = document.getElementById("rightUl");
        var liElement = rightUl.getElementsByTagName("li");
        for (var i = 0; i < liElement.length; i++) {
            var li = liElement[i];
            var checkElement = li.firstElementChild;
            if (!checkElement.checked) {
                checkElement.checked = true;
            }
        }
        goLeft(rightUl);
    }

    function getChecked() {
        var rightUl = document.getElementById("rightUl");
        var liElement = rightUl.getElementsByTagName("li");
        var checked = [];
        for (var i = 0; i < liElement.length; i++) {
            var li = liElement[i];
            var checkBox = li.firstElementChild;
            var lable = li.lastElementChild;
            if (checkBox.checked) {
                checked.push(lable.innerHTML);
            }
        }
        return checked;
    }
</script>
<%--项目中引用的ajaxUpload bug 太多,版本太旧,不支持跨域，这里替换掉--%>
<script type="text/javascript">
    !function (e) {
        "function" == typeof define && define.amd ? define(["jquery"], e) : "object" == typeof module && module.exports ? module.exports = function (t, r) {
            return void 0 === r && (r = "undefined" != typeof window ? require("jquery") : require("jquery")(t)), e(r), r
        } : e(jQuery)
    }(function (e) {
        "use strict";

        function t(t) {
            var r = t.data;
            t.isDefaultPrevented() || (t.preventDefault(), e(t.target).closest("form").ajaxSubmit(r))
        }

        function r(t) {
            var r = t.target, a = e(r);
            if (!a.is("[type=submit],[type=image]")) {
                var n = a.closest("[type=submit]");
                if (0 === n.length) return;
                r = n[0]
            }
            var i = r.form;
            if (i.clk = r, "image" === r.type) if (void 0 !== t.offsetX) i.clk_x = t.offsetX, i.clk_y = t.offsetY; else if ("function" == typeof e.fn.offset) {
                var o = a.offset();
                i.clk_x = t.pageX - o.left, i.clk_y = t.pageY - o.top
            } else i.clk_x = t.pageX - r.offsetLeft, i.clk_y = t.pageY - r.offsetTop;
            setTimeout(function () {
                i.clk = i.clk_x = i.clk_y = null
            }, 100)
        }

        function a() {
            if (e.fn.ajaxSubmit.debug) {
                var t = "[jquery.form] " + Array.prototype.join.call(arguments, "");
                window.console && window.console.log ? window.console.log(t) : window.opera && window.opera.postError && window.opera.postError(t)
            }
        }

        var n = /\r?\n/g, i = {};
        i.fileapi = void 0 !== e('<input type="file">').get(0).files, i.formdata = void 0 !== window.FormData;
        var o = !!e.fn.prop;
        e.fn.attr2 = function () {
            if (!o) return this.attr.apply(this, arguments);
            var e = this.prop.apply(this, arguments);
            return e && e.jquery || "string" == typeof e ? e : this.attr.apply(this, arguments)
        }, e.fn.ajaxSubmit = function (t, r, n, s) {
            function u(r) {
                var a, n, i = e.param(r, t.traditional).split("&"), o = i.length, s = [];
                for (a = 0; a < o; a++) i[a] = i[a].replace(/\+/g, " "), n = i[a].split("="), s.push([decodeURIComponent(n[0]), decodeURIComponent(n[1])]);
                return s
            }

            function c(r) {
                function n(e) {
                    var t = null;
                    try {
                        e.contentWindow && (t = e.contentWindow.document)
                    } catch (e) {
                        a("cannot get iframe.contentWindow document: " + e)
                    }
                    if (t) return t;
                    try {
                        t = e.contentDocument ? e.contentDocument : e.document
                    } catch (r) {
                        a("cannot get iframe.contentDocument: " + r), t = e.document
                    }
                    return t
                }

                function i() {
                    function t() {
                        try {
                            var e = n(v).readyState;
                            a("state = " + e), e && "uninitialized" === e.toLowerCase() && setTimeout(t, 50)
                        } catch (e) {
                            a("Server abort: ", e, " (", e.name, ")"), s(L), j && clearTimeout(j), j = void 0
                        }
                    }

                    var r = p.attr2("target"), i = p.attr2("action"),
                        o = p.attr("enctype") || p.attr("encoding") || "multipart/form-data";
                    w.setAttribute("target", m), l && !/post/i.test(l) || w.setAttribute("method", "POST"), i !== f.url && w.setAttribute("action", f.url), f.skipEncodingOverride || l && !/post/i.test(l) || p.attr({
                        encoding: "multipart/form-data",
                        enctype: "multipart/form-data"
                    }), f.timeout && (j = setTimeout(function () {
                        T = !0, s(A)
                    }, f.timeout));
                    var u = [];
                    try {
                        if (f.extraData) for (var c in f.extraData) f.extraData.hasOwnProperty(c) && (e.isPlainObject(f.extraData[c]) && f.extraData[c].hasOwnProperty("name") && f.extraData[c].hasOwnProperty("value") ? u.push(e('<input type="hidden" name="' + f.extraData[c].name + '">', k).val(f.extraData[c].value).appendTo(w)[0]) : u.push(e('<input type="hidden" name="' + c + '">', k).val(f.extraData[c]).appendTo(w)[0]));
                        f.iframeTarget || h.appendTo(D), v.attachEvent ? v.attachEvent("onload", s) : v.addEventListener("load", s, !1), setTimeout(t, 15);
                        try {
                            w.submit()
                        } catch (e) {
                            document.createElement("form").submit.apply(w)
                        }
                    } finally {
                        w.setAttribute("action", i), w.setAttribute("enctype", o), r ? w.setAttribute("target", r) : p.removeAttr("target"), e(u).remove()
                    }
                }

                function s(t) {
                    if (!x.aborted && !X) {
                        if ((O = n(v)) || (a("cannot access response document"), t = L), t === A && x) return x.abort("timeout"), void S.reject(x, "timeout");
                        if (t === L && x) return x.abort("server abort"), void S.reject(x, "error", "server abort");
                        if (O && O.location.href !== f.iframeSrc || T) {
                            v.detachEvent ? v.detachEvent("onload", s) : v.removeEventListener("load", s, !1);
                            var r, i = "success";
                            try {
                                if (T) throw"timeout";
                                var o = "xml" === f.dataType || O.XMLDocument || e.isXMLDoc(O);
                                if (a("isXml=" + o), !o && window.opera && (null === O.body || !O.body.innerHTML) && --C) return a("requeing onLoad callback, DOM not available"), void setTimeout(s, 250);
                                var u = O.body ? O.body : O.documentElement;
                                x.responseText = u ? u.innerHTML : null, x.responseXML = O.XMLDocument ? O.XMLDocument : O, o && (f.dataType = "xml"), x.getResponseHeader = function (e) {
                                    return {"content-type": f.dataType}[e.toLowerCase()]
                                }, u && (x.status = Number(u.getAttribute("status")) || x.status, x.statusText = u.getAttribute("statusText") || x.statusText);
                                var c = (f.dataType || "").toLowerCase(), l = /(json|script|text)/.test(c);
                                if (l || f.textarea) {
                                    var p = O.getElementsByTagName("textarea")[0];
                                    if (p) x.responseText = p.value, x.status = Number(p.getAttribute("status")) || x.status, x.statusText = p.getAttribute("statusText") || x.statusText; else if (l) {
                                        var m = O.getElementsByTagName("pre")[0], g = O.getElementsByTagName("body")[0];
                                        m ? x.responseText = m.textContent ? m.textContent : m.innerText : g && (x.responseText = g.textContent ? g.textContent : g.innerText)
                                    }
                                } else "xml" === c && !x.responseXML && x.responseText && (x.responseXML = q(x.responseText));
                                try {
                                    M = N(x, c, f)
                                } catch (e) {
                                    i = "parsererror", x.error = r = e || i
                                }
                            } catch (e) {
                                a("error caught: ", e), i = "error", x.error = r = e || i
                            }
                            x.aborted && (a("upload aborted"), i = null), x.status && (i = x.status >= 200 && x.status < 300 || 304 === x.status ? "success" : "error"), "success" === i ? (f.success && f.success.call(f.context, M, "success", x), S.resolve(x.responseText, "success", x), d && e.event.trigger("ajaxSuccess", [x, f])) : i && (void 0 === r && (r = x.statusText), f.error && f.error.call(f.context, x, i, r), S.reject(x, "error", r), d && e.event.trigger("ajaxError", [x, f, r])), d && e.event.trigger("ajaxComplete", [x, f]), d && !--e.active && e.event.trigger("ajaxStop"), f.complete && f.complete.call(f.context, x, i), X = !0, f.timeout && clearTimeout(j), setTimeout(function () {
                                f.iframeTarget ? h.attr("src", f.iframeSrc) : h.remove(), x.responseXML = null
                            }, 100)
                        }
                    }
                }

                var u, c, f, d, m, h, v, x, y, b, T, j, w = p[0], S = e.Deferred();
                if (S.abort = function (e) {
                    x.abort(e)
                }, r) for (c = 0; c < g.length; c++) u = e(g[c]), o ? u.prop("disabled", !1) : u.removeAttr("disabled");
                (f = e.extend(!0, {}, e.ajaxSettings, t)).context = f.context || f, m = "jqFormIO" + (new Date).getTime();
                var k = w.ownerDocument, D = p.closest("body");
                if (f.iframeTarget ? (b = (h = e(f.iframeTarget, k)).attr2("name")) ? m = b : h.attr2("name", m) : (h = e('<iframe name="' + m + '" src="' + f.iframeSrc + '" />', k)).css({
                    position: "absolute",
                    top: "-1000px",
                    left: "-1000px"
                }), v = h[0], x = {
                    aborted: 0,
                    responseText: null,
                    responseXML: null,
                    status: 0,
                    statusText: "n/a",
                    getAllResponseHeaders: function () {
                    },
                    getResponseHeader: function () {
                    },
                    setRequestHeader: function () {
                    },
                    abort: function (t) {
                        var r = "timeout" === t ? "timeout" : "aborted";
                        a("aborting upload... " + r), this.aborted = 1;
                        try {
                            v.contentWindow.document.execCommand && v.contentWindow.document.execCommand("Stop")
                        } catch (e) {
                        }
                        h.attr("src", f.iframeSrc), x.error = r, f.error && f.error.call(f.context, x, r, t), d && e.event.trigger("ajaxError", [x, f, r]), f.complete && f.complete.call(f.context, x, r)
                    }
                }, (d = f.global) && 0 == e.active++ && e.event.trigger("ajaxStart"), d && e.event.trigger("ajaxSend", [x, f]), f.beforeSend && !1 === f.beforeSend.call(f.context, x, f)) return f.global && e.active--, S.reject(), S;
                if (x.aborted) return S.reject(), S;
                (y = w.clk) && (b = y.name) && !y.disabled && (f.extraData = f.extraData || {}, f.extraData[b] = y.value, "image" === y.type && (f.extraData[b + ".x"] = w.clk_x, f.extraData[b + ".y"] = w.clk_y));
                var A = 1, L = 2, F = e("meta[name=csrf-token]").attr("content"),
                    E = e("meta[name=csrf-param]").attr("content");
                E && F && (f.extraData = f.extraData || {}, f.extraData[E] = F), f.forceSync ? i() : setTimeout(i, 10);
                var M, O, X, C = 50, q = e.parseXML || function (e, t) {
                    return window.ActiveXObject ? ((t = new ActiveXObject("Microsoft.XMLDOM")).async = "false", t.loadXML(e)) : t = (new DOMParser).parseFromString(e, "text/xml"), t && t.documentElement && "parsererror" !== t.documentElement.nodeName ? t : null
                }, _ = e.parseJSON || function (e) {
                    return window.eval("(" + e + ")")
                }, N = function (t, r, a) {
                    var n = t.getResponseHeader("content-type") || "", i = ("xml" === r || !r) && n.indexOf("xml") >= 0,
                        o = i ? t.responseXML : t.responseText;
                    return i && "parsererror" === o.documentElement.nodeName && e.error && e.error("parsererror"), a && a.dataFilter && (o = a.dataFilter(o, r)), "string" == typeof o && (("json" === r || !r) && n.indexOf("json") >= 0 ? o = _(o) : ("script" === r || !r) && n.indexOf("javascript") >= 0 && e.globalEval(o)), o
                };
                return S
            }

            if (!this.length) return a("ajaxSubmit: skipping submit process - no element selected"), this;
            var l, f, d, p = this;
            "function" == typeof t ? t = {success: t} : "string" == typeof t || !1 === t && arguments.length > 0 ? (t = {
                url: t,
                data: r,
                dataType: n
            }, "function" == typeof s && (t.success = s)) : void 0 === t && (t = {}), l = t.method || t.type || this.attr2("method"), (d = (d = "string" == typeof (f = t.url || this.attr2("action")) ? e.trim(f) : "") || window.location.href || "") && (d = (d.match(/^([^#]+)/) || [])[1]), t = e.extend(!0, {
                url: d,
                success: e.ajaxSettings.success,
                type: l || e.ajaxSettings.type,
                iframeSrc: /^https/i.test(window.location.href || "") ? "javascript:false" : "about:blank"
            }, t);
            var m = {};
            if (this.trigger("form-pre-serialize", [this, t, m]), m.veto) return a("ajaxSubmit: submit vetoed via form-pre-serialize trigger"), this;
            if (t.beforeSerialize && !1 === t.beforeSerialize(this, t)) return a("ajaxSubmit: submit aborted via beforeSerialize callback"), this;
            var h = t.traditional;
            void 0 === h && (h = e.ajaxSettings.traditional);
            var v, g = [], x = this.formToArray(t.semantic, g, t.filtering);
            if (t.data) {
                var y = e.isFunction(t.data) ? t.data(x) : t.data;
                t.extraData = y, v = e.param(y, h)
            }
            if (t.beforeSubmit && !1 === t.beforeSubmit(x, this, t)) return a("ajaxSubmit: submit aborted via beforeSubmit callback"), this;
            if (this.trigger("form-submit-validate", [x, this, t, m]), m.veto) return a("ajaxSubmit: submit vetoed via form-submit-validate trigger"), this;
            var b = e.param(x, h);
            v && (b = b ? b + "&" + v : v), "GET" === t.type.toUpperCase() ? (t.url += (t.url.indexOf("?") >= 0 ? "&" : "?") + b, t.data = null) : t.data = b;
            var T = [];
            if (t.resetForm && T.push(function () {
                p.resetForm()
            }), t.clearForm && T.push(function () {
                p.clearForm(t.includeHidden)
            }), !t.dataType && t.target) {
                var j = t.success || function () {
                };
                T.push(function (r, a, n) {
                    var i = arguments, o = t.replaceTarget ? "replaceWith" : "html";
                    e(t.target)[o](r).each(function () {
                        j.apply(this, i)
                    })
                })
            } else t.success && (e.isArray(t.success) ? e.merge(T, t.success) : T.push(t.success));
            if (t.success = function (e, r, a) {
                for (var n = t.context || this, i = 0, o = T.length; i < o; i++) T[i].apply(n, [e, r, a || p, p])
            }, t.error) {
                var w = t.error;
                t.error = function (e, r, a) {
                    var n = t.context || this;
                    w.apply(n, [e, r, a, p])
                }
            }
            if (t.complete) {
                var S = t.complete;
                t.complete = function (e, r) {
                    var a = t.context || this;
                    S.apply(a, [e, r, p])
                }
            }
            var k = e("input[type=file]:enabled", this).filter(function () {
                    return "" !== e(this).val()
                }).length > 0, D = "multipart/form-data", A = p.attr("enctype") === D || p.attr("encoding") === D,
                L = i.fileapi && i.formdata;
            a("fileAPI :" + L);
            var F, E = (k || A) && !L;
            !1 !== t.iframe && (t.iframe || E) ? t.closeKeepAlive ? e.get(t.closeKeepAlive, function () {
                F = c(x)
            }) : F = c(x) : F = (k || A) && L ? function (r) {
                for (var a = new FormData, n = 0; n < r.length; n++) a.append(r[n].name, r[n].value);
                if (t.extraData) {
                    var i = u(t.extraData);
                    for (n = 0; n < i.length; n++) i[n] && a.append(i[n][0], i[n][1])
                }
                t.data = null;
                var o = e.extend(!0, {}, e.ajaxSettings, t, {
                    contentType: !1,
                    processData: !1,
                    cache: !1,
                    type: l || "POST"
                });
                t.uploadProgress && (o.xhr = function () {
                    var r = e.ajaxSettings.xhr();
                    return r.upload && r.upload.addEventListener("progress", function (e) {
                        var r = 0, a = e.loaded || e.position, n = e.total;
                        e.lengthComputable && (r = Math.ceil(a / n * 100)), t.uploadProgress(e, a, n, r)
                    }, !1), r
                }), o.data = null;
                var s = o.beforeSend;
                return o.beforeSend = function (e, r) {
                    t.formData ? r.data = t.formData : r.data = a, s && s.call(this, e, r)
                }, e.ajax(o)
            }(x) : e.ajax(t), p.removeData("jqxhr").data("jqxhr", F);
            for (var M = 0; M < g.length; M++) g[M] = null;
            return this.trigger("form-submit-notify", [this, t]), this
        }, e.fn.ajaxForm = function (n, i, o, s) {
            if (("string" == typeof n || !1 === n && arguments.length > 0) && (n = {
                url: n,
                data: i,
                dataType: o
            }, "function" == typeof s && (n.success = s)), n = n || {}, n.delegation = n.delegation && e.isFunction(e.fn.on), !n.delegation && 0 === this.length) {
                var u = {s: this.selector, c: this.context};
                return !e.isReady && u.s ? (a("DOM not ready, queuing ajaxForm"), e(function () {
                    e(u.s, u.c).ajaxForm(n)
                }), this) : (a("terminating; zero elements found by selector" + (e.isReady ? "" : " (DOM not ready)")), this)
            }
            return n.delegation ? (e(document).off("submit.form-plugin", this.selector, t).off("click.form-plugin", this.selector, r).on("submit.form-plugin", this.selector, n, t).on("click.form-plugin", this.selector, n, r), this) : this.ajaxFormUnbind().on("submit.form-plugin", n, t).on("click.form-plugin", n, r)
        }, e.fn.ajaxFormUnbind = function () {
            return this.off("submit.form-plugin click.form-plugin")
        }, e.fn.formToArray = function (t, r, a) {
            var n = [];
            if (0 === this.length) return n;
            var o, s = this[0], u = this.attr("id"),
                c = t || void 0 === s.elements ? s.getElementsByTagName("*") : s.elements;
            if (c && (c = e.makeArray(c)), u && (t || /(Edge|Trident)\//.test(navigator.userAgent)) && (o = e(':input[form="' + u + '"]').get()).length && (c = (c || []).concat(o)), !c || !c.length) return n;
            e.isFunction(a) && (c = e.map(c, a));
            var l, f, d, p, m, h, v;
            for (l = 0, h = c.length; l < h; l++) if (m = c[l], (d = m.name) && !m.disabled) if (t && s.clk && "image" === m.type) s.clk === m && (n.push({
                name: d,
                value: e(m).val(),
                type: m.type
            }), n.push({name: d + ".x", value: s.clk_x}, {
                name: d + ".y",
                value: s.clk_y
            })); else if ((p = e.fieldValue(m, !0)) && p.constructor === Array) for (r && r.push(m), f = 0, v = p.length; f < v; f++) n.push({
                name: d,
                value: p[f]
            }); else if (i.fileapi && "file" === m.type) {
                r && r.push(m);
                var g = m.files;
                if (g.length) for (f = 0; f < g.length; f++) n.push({
                    name: d,
                    value: g[f],
                    type: m.type
                }); else n.push({name: d, value: "", type: m.type})
            } else null !== p && void 0 !== p && (r && r.push(m), n.push({
                name: d,
                value: p,
                type: m.type,
                required: m.required
            }));
            if (!t && s.clk) {
                var x = e(s.clk), y = x[0];
                (d = y.name) && !y.disabled && "image" === y.type && (n.push({
                    name: d,
                    value: x.val()
                }), n.push({name: d + ".x", value: s.clk_x}, {name: d + ".y", value: s.clk_y}))
            }
            return n
        }, e.fn.formSerialize = function (t) {
            return e.param(this.formToArray(t))
        }, e.fn.fieldSerialize = function (t) {
            var r = [];
            return this.each(function () {
                var a = this.name;
                if (a) {
                    var n = e.fieldValue(this, t);
                    if (n && n.constructor === Array) for (var i = 0, o = n.length; i < o; i++) r.push({
                        name: a,
                        value: n[i]
                    }); else null !== n && void 0 !== n && r.push({name: this.name, value: n})
                }
            }), e.param(r)
        }, e.fn.fieldValue = function (t) {
            for (var r = [], a = 0, n = this.length; a < n; a++) {
                var i = this[a], o = e.fieldValue(i, t);
                null === o || void 0 === o || o.constructor === Array && !o.length || (o.constructor === Array ? e.merge(r, o) : r.push(o))
            }
            return r
        }, e.fieldValue = function (t, r) {
            var a = t.name, i = t.type, o = t.tagName.toLowerCase();
            if (void 0 === r && (r = !0), r && (!a || t.disabled || "reset" === i || "button" === i || ("checkbox" === i || "radio" === i) && !t.checked || ("submit" === i || "image" === i) && t.form && t.form.clk !== t || "select" === o && -1 === t.selectedIndex)) return null;
            if ("select" === o) {
                var s = t.selectedIndex;
                if (s < 0) return null;
                for (var u = [], c = t.options, l = "select-one" === i, f = l ? s + 1 : c.length, d = l ? s : 0; d < f; d++) {
                    var p = c[d];
                    if (p.selected && !p.disabled) {
                        var m = p.value;
                        if (m || (m = p.attributes && p.attributes.value && !p.attributes.value.specified ? p.text : p.value), l) return m;
                        u.push(m)
                    }
                }
                return u
            }
            return e(t).val().replace(n, "\r\n")
        }, e.fn.clearForm = function (t) {
            return this.each(function () {
                e("input,select,textarea", this).clearFields(t)
            })
        }, e.fn.clearFields = e.fn.clearInputs = function (t) {
            var r = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i;
            return this.each(function () {
                var a = this.type, n = this.tagName.toLowerCase();
                r.test(a) || "textarea" === n ? this.value = "" : "checkbox" === a || "radio" === a ? this.checked = !1 : "select" === n ? this.selectedIndex = -1 : "file" === a ? /MSIE/.test(navigator.userAgent) ? e(this).replaceWith(e(this).clone(!0)) : e(this).val("") : t && (!0 === t && /hidden/.test(a) || "string" == typeof t && e(this).is(t)) && (this.value = "")
            })
        }, e.fn.resetForm = function () {
            return this.each(function () {
                var t = e(this), r = this.tagName.toLowerCase();
                switch (r) {
                    case"input":
                        this.checked = this.defaultChecked;
                    case"textarea":
                        return this.value = this.defaultValue, !0;
                    case"option":
                    case"optgroup":
                        var a = t.parents("select");
                        return a.length && a[0].multiple ? "option" === r ? this.selected = this.defaultSelected : t.find("option").resetForm() : a.resetForm(), !0;
                    case"select":
                        return t.find("option").each(function (e) {
                            if (this.selected = this.defaultSelected, this.defaultSelected && !t[0].multiple) return t[0].selectedIndex = e, !1
                        }), !0;
                    case"label":
                        var n = e(t.attr("for")), i = t.find("input,select,textarea");
                        return n[0] && i.unshift(n[0]), i.resetForm(), !0;
                    case"form":
                        return ("function" == typeof this.reset || "object" == typeof this.reset && !this.reset.nodeType) && this.reset(), !0;
                    default:
                        return t.find("form,input,label,select,textarea").resetForm(), !0
                }
            })
        }, e.fn.enable = function (e) {
            return void 0 === e && (e = !0), this.each(function () {
                this.disabled = !e
            })
        }, e.fn.selected = function (t) {
            return void 0 === t && (t = !0), this.each(function () {
                var r = this.type;
                if ("checkbox" === r || "radio" === r) this.checked = t; else if ("option" === this.tagName.toLowerCase()) {
                    var a = e(this).parent("select");
                    t && a[0] && "select-one" === a[0].type && a.find("option").selected(!1), this.selected = t
                }
            })
        }, e.fn.ajaxSubmit.debug = !1
    });
</script>
</body>
</html>